package com.dreamlin.okhttp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.TextView;

import java.io.IOException;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import retrofit2.Response;

public class MainActivity extends AppCompatActivity {

    private Handler mainHandler = new Handler(Looper.getMainLooper());
    private TextView tvHello;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        tvHello = findViewById(R.id.tvHello);
        Api api = OkHttpHelper.INSTANCE.apiService("https://gank.io/api/");
        Thread thread = new Thread(() -> {
            try {
                Response<BaseEntity<List<GirlEntity>>> response = api.listGirls("2222").execute();
                List<GirlEntity> result = response.body().result;
                RequestBody requestBody = RequestBody.create("jsonStr", MediaType.get("application/json"));
                mainHandler.post(() -> {
//                    tvHello.setText(
//                            result.toString()
//                    );
                });
            } catch (IOException e) {
                e.printStackTrace();
            }

        });
        thread.start();
    }
}